<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/1/8 0008
  Time: 14:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>专家管理</title>
</head>

<<body style="padding:0px" >
<style>
    .color_001{
        color:#093;
    }
    .color_002{
        color: #f93;
    }
    .color_003{
        color: #f30;
    }

</style>
<script>
    function formatterImg(value) {
        if (value != null) {
            return '<img height="25px" src="' + value + '" alt="" />';
        } else {
            return '';
        }
    }
    var IsCheckFlag = true; //标示是否是勾选复选框选中行的，true - 是 , false - 否
    $(function(){
        $("#specialist_tt").datagrid({//数据表格
            url:"${path}/specialist/specialist.do",
            width:"100%",
            height:"755px",
            fitColumns: true,//宽度自适应
            align:"center",
            loadMsg:"正在处理，请等待......",
            striped: true,//true是否把一行条文化
            idField:"id",//唯一性标示字段
            pagination:true,//显示分页栏
            rownumbers:true,//显示行号
            singleSelect:true,//true只可以选中一行
            pageSize:20,
            frozenColumns:[[//冻结字段
                {field:"ck",checkbox:true}
            ]],
            onClickCell: function (rowIndex, field, value) {
                IsCheckFlag = false;
            },
            onSelect: function (rowIndex, rowData) {
                if (!IsCheckFlag) {
                    IsCheckFlag = true;
                    $("#seller_tt").datagrid("unselectRow", rowIndex);
                }
            },
            onUnselect: function (rowIndex, rowData) {
                if (!IsCheckFlag) {
                    IsCheckFlag = true;
                    $("#seller_tt").datagrid("selectRow", rowIndex);
                }
            },
            columns:[[//未冻结字段
                {field:"userPhone",title:"专家账号",width:60},
                {field:"name",title:"专家名字",width:60},
                {field:"sellerName",title:"所属医院",width:60},
                {field:"professionPosition",title:"职位",width:60},
                {field:"hospitalDepartmentName",title:"所属科室",width:60},
                {field:"tel",title:"联系电话",width:60},
                {field:"img",title:"专家图片",width:60,formatter:formatterImg},
                {field:"verifyType",title:"审核状态",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font class='color_002'>待审核</font>";
                        }else if(value=="1"){
                            return "<font class='color_001'>通过</font>";
                        }else if(value=="2"){
                            return "<font class='color_003'>拒绝</font>";
                        }
                    }
                },
                {field:"status",title:"状态",width:30,
                    formatter:function(value,rowData,rowIndex){  //function里面的三个参数代表当前字段值，当前行数据对象，行号（行号从0开始）
                        if(value=="0"){
                            return "<font class='color_003'>禁用</font>";
                        }else if(value=="1") {
                            return "<font class='color_001'>正常</font>";
                        }
                    }
                },
                {field:"ord",title:"排序",width:30},
                {field:"virtaulCommentCount",title:"虚拟评论数量",width:35},
                {field:"commentCount",title:"评论数量",width:30},
                {field:"commentScore",title:"评分",width:20},
                {field:"createDate",title:"创建时间",width:60,formatter: formatDatebox}
            ]],
            toolbar:[
                <shiro:hasPermission name="/specialist/add.do">
                "-",
                {//工具条
                    text:"添加",
                    iconCls:"icon-add",
                    handler:function(){
                        var msg="添加";
                        $.modalDialog({
                            title : msg+'专家',
                            id:'modelAdd',
                            width : 1000,
                            height : 600,
                            href : '${path }/specialist/gotoAddSpecialist.do'
                        });

                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/specialist/edit.do">
                {//工具条
                    text:"修改",
                    iconCls:"icon-edit",
                    handler:function(){
                        var rowsData = $("#specialist_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作专家',"info");
                        }else{
                            var msg="修改";
                            $.modalDialog({
                                title : msg+'专家',
                                id:'modelEdit',
                                width : 1000,
                                height : 600,
                                href : '${path }/specialist/gotoEditSpecialist.do?specialistId='+rowsData[0].id
                            });
                        }

                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/specialist/delete.do">
                {
                    text:"删除",
                    iconCls:"icon-remove",
                    handler:function(){
                        var rowsData = $("#specialist_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作专家',"info");

                        }else{
                            if(rowsData[0].status!=0){
                                var msg="正常状态"
                                $.messager.alert('系统提示','该专家属于'+msg,"info");
                                return;
                            }else{
                                $.messager.confirm("系统提示", "<p class='tipInfo'>你确定要删除吗?</p>",function(data){
                                    $.messager.progress();
                                    if(data){//判断是否删除
                                        if (rowsData){//判断是否找到当前行，找到后异步形式从数据库中删除当前记录
                                            var specialistId=rowsData[0].id;
                                            console.log(SpecialistId);
                                            $.ajax({
                                                type: "POST",
                                                dataType: "JSON",
                                                url: "${path}/specialist/delete.do",
                                                data: {"specialistId":specialistId},
                                                success: function(data){
                                                    $.messager.progress("close");
                                                    if(data.success){
                                                        $.messager.show({
                                                            title:"系统提示",
                                                            msg:"删除成功!",
                                                            timeout:600,
                                                            style:"left:30%;top:10%",
                                                            showType:"fade"
                                                        });
                                                        $("#specialist_tt").datagrid("clearSelections");//删除后取消所有选项
                                                        $("#specialist_tt").datagrid("reload");
                                                    }else{
                                                        $.messager.progress("close");
                                                        $.messager.alert("系统提示", data.msg,"error");
                                                    }
                                                },
                                                error:function(){
                                                    $.messager.progress("close");
                                                    $.messager.alert("系统提示", "服务器连接失败!","error");
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/specialist/checkSpecialist.do">
                {//工具条
                    text:"审核",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#specialist_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作专家',"info");
                        }else{
                            $.modalDialog({
                                title : '审核专家',
                                id:'modelCheckSpecialistId',
                                width : 300,
                                height :150,
                                href : '${path }/specialist/gotoCheckSpecialist.do?specialistId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                <shiro:hasPermission name="/specialist/checkStauteSpecialist.do">
                {//工具条
                    text:"启用|禁用",
                    iconCls:"icon-tip",
                    handler:function(){
                        var rowsData = $("#specialist_tt").datagrid("getSelections");//找到所有选中的行
                        if(rowsData.length<=0){
                            $.messager.alert('系统提示','请先选择要操作专家',"info");
                        }else{
                            $.modalDialog({
                                title : '启用|禁用',
                                id:'modelCheckStauteSpecialist',
                                width : 300,
                                height : 150,
                                href : '${path }/specialist/gotoCheckStauteSpecialist.do?specialistId='+rowsData[0].id
                            });
                        }
                    }
                },"-",
                </shiro:hasPermission>
                {text:"刷新",
                    iconCls:"icon-reload",
                    handler:function(){
                        $("#specialist_tt").datagrid("clearSelections");//删除后取消所有选项
                        $("#specialist_tt").datagrid("reload");
                    }
                },"-",
            ]
        });
        //扩展的Date的format方法(上述插件实现) 日期转换格式
        Date.prototype.format = function (format) {
            var o = {
                "M+": this.getMonth() + 1, // month
                "d+": this.getDate(), // day
                "h+": this.getHours(), // hour
                "m+": this.getMinutes(), // minute
                "s+": this.getSeconds(), // second
                "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
                "S": this.getMilliseconds()
                // millisecond
            }
            if (/(y+)/.test(format))
                format = format.replace(RegExp.$1, (this.getFullYear() + "")
                    .substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }
        //调用日期转化格式方法
        function formatDatebox(value) {

            if (value == null || value == '') {
                return '';
            }
            var dt;
            if (value instanceof Date) {
                dt = value;
            } else {
                dt = new Date(value);
            }

            return dt.format("yyyy-MM-dd hh:mm:ss");
        }
    });
    //刷新
    function reloadSpecialistDataGrid() {
        $('#specialist_tt').datagrid('reload');
    }
    //关闭窗口
    function closeWin(str) {
        $('#'+str).dialog("close");
    }
    //重置
    function reset() {
        $("#specialistzh").val("");
        $("#specialistName").val("");
        $("#specialistVerifyType").val("-1");
        $("#specialistStatus").val("-1");
        window.location.href="${path}/specialist/gotoSpecialist.do";
        $("#specialist_tt").datagrid('reload');
    }
    //查询
    function queryingSpecialist(){
        var queryParams = {
            phone:$("#specialistzh").val(),
            specialistName:$("#specialistName").val(),
            verifyType:$("#specialistVerifyType").val(),
            status:$("#specialistStatus").val(),
        };
        var options = $("#specialist_tt").datagrid('getPager').data("pagination").options;
        options.pageNumber = 1;
        //重新加载
        $("#specialist_tt").datagrid('options').url = "${path}/specialist/specialist.do";
        $("#specialist_tt").datagrid('options').queryParams = queryParams;
        $("#specialist_tt").datagrid('reload');
    }

</script>
<h2 style="margin-bottom: 0px">专家列表</h2>
<div style="border:3px solid rgb(95,158,160)">
</div>

<div class="main" style="width: 100%; margin: 20px auto ">
    <style type="text/css">
        .searchTab{font:12px arial,helvetica,sans-serif;border:2px solid rgb(95,158,160)}
        .searchTab td{font:100% arial,helvetica,sans-serif;height:30px;padding:5px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
        .searchTab{width:100%;border-collapse:collapse}
        .searchTab td{border:0px solid #e0e0e0;padding-left:5px;text-align: right}
    </style>
    <table class="searchTab">
        <tr>
            <td class="search_toright_td"  style="width:60px;">专家账号：</td>
            <td class="search_toleft_td" style="width:80px;"><input type="text" style="width:90px;" id="specialistzh" name="specialistzh" class="searchTabinput"/></td>
            <td class="search_toright_td" style="width:60px;">专家姓名：</td>
            <td class="search_toleft_td" style="width:80px;"><input type="text" style="width:90px;" id="specialistName" name="specialistName" class="searchTabinput"/></td>
            <td class="search_toright_td" style="width:60px;">审核状态：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="specialistVerifyType" style="width:80px;" class="querySelect">
                    <option value="-1">--请选择--</option>
                    <option value="0">待审核</option>
                    <option value="1">通过</option>
                    <option value="2">拒绝</option>
                </select>
            <td class="search_toright_td" style="width:60px;">状态：</td>
            <td class="search_toleft_td" style="width:80px;">
                <select id="specialistStatus" style="width:80px;" class="querySelect">
                    <option value="-1">--请选择--</option>
                    <option value="0">禁用</option>
                    <option value="1">正常</option>
                </select>
            </td>
            <td class="search_toleft_td">&nbsp;&nbsp;
                <a id="btnCancel" class="easyui-linkbutton" icon="icon-search" href="javascript:queryingSpecialist()">查询</a>
                <a id="btnCance2" class="easyui-linkbutton"  iconCls="icon-undo" href="javascript:reset()">重置</a>
            </td>
        </tr>
    </table>
    <table id="specialist_tt" style="border: 1px solid rgb(95,158,160);white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
    </table>

</div>
</body>
</html>
